import tool from "../../modules/tool"

// components/index_statistics/index_statistics.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false,
    data: {},
    chartButtons: [{
        title: '各校区类别反馈分布条形图',
        callBack: () => tool.handleShowStatisticsPage('feedBack_campusCategory')
      },
      {
        title: '巡查状态分布饼图',
        callBack: () => tool.handleShowStatisticsPage('patrol_total')
      },
      {
        title: '未完成巡查状态分布饼图',
        callBack: () => tool.handleShowStatisticsPage('patrol_preToDo')
      },
      {
        title: '已结束巡查状态分布饼图',
        callBack: () => tool.handleShowStatisticsPage('patrol_finished')
      },
      {
        title: '各校区巡查数量饼图',
        callBack: () => tool.handleShowStatisticsPage('patrol_campus')
      },
      {
        title: '各类别巡查数量饼图',
        callBack: () => tool.handleShowStatisticsPage('patrol_category')
      },
      {
        title: '指定校区类别巡查状态饼图',
        callBack: async () => {
          let form = {
            campusId: undefined,
            categoryId: undefined
          }
          tool.select.campus(async (e1) => {
            form.campusId = e1.id
            await tool.wait(0.3)
            tool.select.category(async (e2) => {
              form.categoryId = e2.id
              wx.navigateBack({
                delta: 2
              })
              await tool.wait(0.3)
              tool.handleShowStatisticsPage('patrol_campusCategory', form)
            })
          })
        }
      },
      {
        title: '指定用户巡查状态分布饼图',
        callBack: () => tool.page.userSearch(['搜索并选择一个用户'], (e) => {
          e = e[0]
          tool.handleShowStatisticsPage('patrol_user', {
            userId: e.id
          })
        }, false, false)
      },
      {
        title: '指定负责人处理评价分布饼图',
        callBack: () => tool.page.userSearch(['搜索并选择一个用户'], (e) => {
          e = e[0]
          tool.handleShowStatisticsPage('patrol_handler', {
            userId: e.id
          })
        }, false, false)
      },
      {
        title: '指定负责人审核情况饼图',
        callBack: () => tool.page.userSearch(['搜索并选择一个用户'], (e) => {
          e = e[0]
          tool.handleShowStatisticsPage('patrol_handlerReview', {
            userId: e.id
          })
        }, false, false)
      },
      {
        title: '指定负责人处理时长分布饼图',
        callBack: () => tool.page.userSearch(['搜索并选择一个用户'], (e) => {
          e = e[0]
          tool.handleShowStatisticsPage('patrol_handlerEndTime', {
            userId: e.id
          })
        }, false, false)
      }
    ]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    handeClickPatrolNum(e) {
      e = e.currentTarget.dataset
      if (e.type) {
        tool.page.searchPatrol({
          status: e.type
        })
      } else {
        tool.page.searchPatrol({})
      }
    },
    handleClickFeedBackTotal() {
      tool.feedback.showAllOrSearchOptions()
    },
    handleClickFeedBackLastDayNew() {
      tool.page.searchFeedBack({
        createdAtStart: this.data.data.feedBack_lastDayStartTime
      }, '近1天新增反馈')
    }
  },

  async attached() {
    let re = await tool.requestData('/statistics/home', {}, 'get')
    if (re.status) {
      this.setData({
        data: re.data,
        show: true
      })
    } else {
      tool.handleShowToast(`${re.content}`, 'error')
    }
  }
})